import 'package:flutter/material.dart';

import 'package:my_flutter_github/test/TabBarPageFirst.dart';
import 'package:my_flutter_github/test/TabBarPageSecond.dart';
import 'package:my_flutter_github/test/TabBarPageThree.dart';
import 'package:my_flutter_github/test/TabBarPageFour.dart';

import 'package:my_flutter_github/widgets/TabBarWidget.dart';

class TabBarTopPageWidget extends StatefulWidget {
  @override
  _TabBarTopPageWidgetState createState() => _TabBarTopPageWidgetState();
}

class _TabBarTopPageWidgetState extends State<TabBarTopPageWidget> {
  final PageController topPageController = new PageController();

  final List<String> tab = [
    "111",
    "222",
    "333",
    "444",
    "555",
    "666",
    "777",
    "888",
    "999",
    "000"
  ];

  _createTab() {
    List<Widget> list = new List();
    for (int i = 0; i < tab.length; i++) {
//      FlatButton flatButton = new FlatButton(
//          onPressed: () {
//            print("top flat button click:" + i.toString());
//            topPageController.jumpTo(MediaQuery.of(context).size.width * i);
//          },
//          child: new Text(
//            tab[i],
//            maxLines: 1,
//          ));
//
//      list.add(flatButton);

    print("tab[$i]:${tab[i]}");

      list.add(new FlatButton(
          onPressed: (){
            print("top flat button click:" + i.toString());
            topPageController.jumpTo(MediaQuery.of(context).size.width * i);
          },
          child: new Text(
            tab[i],
            style: TextStyle(color: Colors.white),
            maxLines: 1,
          )));
    }

    return list;
  }

  _createPage(){
    return [
      new TabBarPageFirst(),
      new PageBarPageSecond(),
      new TabBarPageThree(),
      new TabBarPageFour(),
      new TabBarPageFirst(),
      new PageBarPageSecond(),
      new TabBarPageThree(),
      new TabBarPageFour(),
      new TabBarPageFirst(),
      new PageBarPageSecond(),
    ];
  }

  @override
  Widget build(BuildContext context) {
    return new TabBarWidget(
      type: TabBarWidget.TAB_TOP,
      tabItems: _createTab(),
      tabViews: _createPage(),
      pageController: topPageController,
      backgroundColor: Colors.lightBlue,
      indicatorColor: Colors.white,
      title: new Text("Top Page Demo"),
    );
  }
}
